package com.acxiom.bsh.logger;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.LoggerFactory;

import com.acxiom.bsh.constants.CommonConstant;

public class LoggerManager {
	private LoggerManager() {

	}

	// The map for loggers. Key is logger name and value is the AcxmLogger
	// instance.
	private static Map<String, BshLogger> loggerMap;

	static {
		loggerMap = new HashMap<String, BshLogger>();
	}

	/**
	 * Return the common logger defined in logger property file
	 * 
	 * @return
	 */
	public static BshLogger getCommonLogger() {
		return getLogger(CommonConstant.LOGGER_NAME_COMMON);
	}

	public static BshLogger getErrorLogger() {
		return getLogger(CommonConstant.LOGGER_NAME_EXCEPTION);
	}

	public static BshLogger getApiLogger() {
		return getLogger(CommonConstant.LOGGER_NAME_API);
	}
	
	/**
	 * Return the logger by logger name defined in logger property file
	 * 
	 * @param loggerName
	 * @return
	 */
	public static BshLogger getLogger(String loggerName) {
		if (loggerMap.containsKey(loggerName)) {
			return loggerMap.get(loggerName);
		} else {
			BshLogger logger = new BshLogger(LoggerFactory.getLogger(loggerName));
			loggerMap.put(loggerName, logger);
			return logger;
		}
	}
}
